package com.yfp.operation.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.operation.domain.dto.ClientIntegralListDTO;
import com.yfp.operation.domain.dto.IntegralHistoryDTO;
import com.yfp.operation.domain.vo.ClientIntegralListVO;
import com.yfp.operation.domain.vo.IntegralHistoryVO;
import com.yfp.operation.service.ClientIntegralService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @version 1.0
 * @date 2025-03-06 14:18
 */
@RestController
@RequestMapping("/clientIntegral")
@Tag(name = "客户积分")
public class ClientIntegralController extends BaseController {

    @Resource
    private ClientIntegralService clientIntegralService;


    @GetMapping
    @Operation(summary = "积分列表")
    public TableDataInfo<ClientIntegralListVO> clientIntegralList(ClientIntegralListDTO clientIntegralListDTO) {
        startPage();
        List<ClientIntegralListVO> list = clientIntegralService.clientIntegralList(clientIntegralListDTO);
        TableDataInfo dataTable = getDataTable(list);
        list =  clientIntegralService.clientIntegralListComplement(list);
        dataTable.setRows(list);
        return dataTable;
    }


    @GetMapping("/history")
    @Operation(summary = "历史记录")
    public TableDataInfo<IntegralHistoryVO> integralHistory(IntegralHistoryDTO integralHistoryDTO){
        startPage();
        List<IntegralHistoryVO> list = clientIntegralService.integralHistory(integralHistoryDTO);
        TableDataInfo dataTable = getDataTable(list);
        list = clientIntegralService.integralHistoryComplement(list);
        dataTable.setRows(list);
        return dataTable;
    }


    @PostMapping("/giveIntegral")
    @Operation(summary = "订单完成赠送积分")
    public R<Void> giveIntegral(@RequestParam("orderId") String orderId){
        clientIntegralService.giveIntegral(orderId);
        return R.ok();
    }




}
